home *** CD-ROM | disk | FTP | other *** search
/ Aminet 44 / Aminet 44 (2001)(GTI - Schatztruhe)[!][Aug 2001].iso / Aminet / comm / mail / YAM23src.lha / Source / YAM_ER.c < prev    next >
C/C++ Source or Header  |  2001-05-08  |  6KB  |  156 lines

  1. /***************************************************************************
  2.  
  3.  YAM - Yet Another Mailer
  4.  Copyright (C) 1995-2000 by Marcel Beck <mbeck@yam.ch>
  5.  Copyright (C) 2000-2001 by YAM Open Source Team
  6.  
  7.  This program is free software; you can redistribute it and/or modify
  8.  it under the terms of the GNU General Public License as published by
  9.  the Free Software Foundation; either version 2 of the License, or
  10.  (at your option) any later version.
  11.  
  12.  This program is distributed in the hope that it will be useful,
  13.  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  GNU General Public License for more details.
  16.  
  17.  You should have received a copy of the GNU General Public License
  18.  along with this program; if not, write to the Free Software
  19.  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  20.  
  21.  YAM Official Support Site :  http://www.yam.ch
  22.  YAM OpenSource project    :  http://sourceforge.net/projects/yamos/
  23.  
  24.  $Id: YAM_ER.c,v 1.7 2001/05/08 22:27:37 damato Exp $
  25.  
  26. ***************************************************************************/
  27.  
  28. #include "YAM.h"
  29.  
  30. /* local protos */
  31. LOCAL struct ER_ClassData *ER_New(void);
  32.  
  33. /***************************************************************************
  34.  Module: Error window
  35. ***************************************************************************/
  36.  
  37. /// ER_NewError
  38. //  Adds a new error message and displays it
  39. void ER_NewError(char *error, char *arg1, char *arg2)
  40. {
  41.    static char label[SIZE_SMALL];
  42.    char buf[SIZE_LARGE];
  43.    struct ER_GUIData *gui;
  44.    int i;
  45.  
  46.    G->Error = TRUE;
  47.    if (!G->ER)
  48.    {
  49.       if (!(G->ER = ER_New())) return;
  50.       if (!SafeOpenWindow(G->ER->GUI.WI)) { DisposeModule(&G->ER); return; }
  51.    }
  52.    gui = &(G->ER->GUI);
  53.    if (error)
  54.    {
  55.       if (++G->ER_NumErr > MAXERR)
  56.       {
  57.          free(G->ER_Message[0]);
  58.          for (--G->ER_NumErr, i = 1; i < G->ER_NumErr; i++) G->ER_Message[i-1] = G->ER_Message[i];
  59.       }
  60.       SPrintF(buf, error, arg1, arg2); strcat(buf, "\n\n(");
  61. //      strcat(buf, DateStamp2String(NULL, DSS_DATE)); strcat(buf, " ");
  62. //      strcat(buf, DateStamp2String(NULL, DSS_TIME)); strcat(buf, ")");
  63.       strcat(buf, DateStamp2String(NULL, C->SwatchBeat ? DSS_DATEBEAT : DSS_DATETIME));
  64.       strcat(buf, ")");
  65.       strcpy(G->ER_Message[G->ER_NumErr-1] = malloc(strlen(buf)+1), buf);
  66.    }
  67.    SPrintF(label, "\033c%s %%ld/%ld", GetStr(MSG_ErrorReq), G->ER_NumErr);
  68.    set(gui->NB_ERROR, MUIA_Numeric_Format, label);
  69.    set(gui->NB_ERROR, MUIA_Numeric_Min, 1);
  70.    set(gui->NB_ERROR, MUIA_Numeric_Max, G->ER_NumErr);
  71.    set(gui->NB_ERROR, MUIA_Numeric_Value, G->ER_NumErr);
  72.    if (G->MA) set(G->MA->GUI.MI_ERRORS, MUIA_Menuitem_Enabled, TRUE);
  73. }
  74.  
  75. ///
  76. /// ER_SelectFunc
  77. //  Displays an earlier error message
  78. void SAVEDS ASM ER_SelectFunc(REG(a1,int *arg))
  79. {
  80.    int value = *arg;
  81.    set(G->ER->GUI.BT_NEXT, MUIA_Disabled, value == G->ER_NumErr);
  82.    set(G->ER->GUI.BT_PREV, MUIA_Disabled, value == 1);
  83.    set(G->ER->GUI.LV_ERROR, MUIA_Floattext_Text, G->ER_Message[value-1]);
  84. }
  85. MakeHook(ER_SelectHook, ER_SelectFunc);
  86.  
  87. ///
  88. /// ER_CloseFunc
  89. //  Closes error window
  90. void SAVEDS ASM ER_CloseFunc(REG(a1,int *arg))
  91. {
  92.    set(G->ER->GUI.WI, MUIA_Window_Open, FALSE);
  93.    if (*arg)
  94.    {
  95.       while (G->ER_NumErr) free(G->ER_Message[--G->ER_NumErr]);
  96.       if (G->MA) set(G->MA->GUI.MI_ERRORS, MUIA_Menuitem_Enabled, FALSE);
  97.    }
  98.    DisposeModulePush(&G->ER);
  99. }
  100. MakeHook(ER_CloseHook, ER_CloseFunc);
  101. ///
  102.  
  103. /*** GUI***/
  104. /// ER_New
  105. //  Creates error window
  106. LOCAL struct ER_ClassData *ER_New(void)
  107. {
  108.    struct ER_ClassData *data;
  109.  
  110.    if (data = calloc(1,sizeof(struct ER_ClassData)))
  111.    {
  112.       APTR bt_close, bt_clear;
  113.       data->GUI.WI = WindowObject,
  114.          MUIA_Window_Title, GetStr(MSG_ER_ErrorMessages),
  115.          MUIA_Window_ID, MAKE_ID('E','R','R','O'),
  116.          WindowContents, VGroup,
  117.             Child, HGroup,
  118.                Child, data->GUI.BT_PREV = MakeButton(GetStr(MSG_ER_PrevError)),
  119.                Child, data->GUI.NB_ERROR = NumericbuttonObject,
  120.                   MUIA_Numeric_Min, 0,
  121.                   MUIA_Numeric_Value, 0,
  122.                   MUIA_Numeric_Format, "Error %%ld/%ld",
  123.                   MUIA_CycleChain, TRUE,
  124.                End,
  125.                Child, data->GUI.BT_NEXT = MakeButton(GetStr(MSG_ER_NextError)),
  126.             End,
  127.             Child, ListviewObject,
  128.                MUIA_Listview_Input, FALSE,
  129.                MUIA_CycleChain, 1,
  130.                MUIA_Listview_List, data->GUI.LV_ERROR = FloattextObject,
  131.                   ReadListFrame,
  132.                End,
  133.             End,
  134.             Child, ColGroup(2),
  135.                Child, bt_clear = MakeButton(GetStr(MSG_ER_Clear)),
  136.                Child, bt_close = MakeButton(GetStr(MSG_ER_Close)),
  137.             End,
  138.          End,
  139.       End;
  140.       if (data->GUI.WI)
  141.       {
  142.          DoMethod(G->App, OM_ADDMEMBER, data->GUI.WI);
  143.          DoMethod(data->GUI.BT_PREV ,MUIM_Notify,MUIA_Pressed            ,FALSE         ,data->GUI.NB_ERROR     ,2,MUIM_Numeric_Decrease,1);
  144.          DoMethod(data->GUI.BT_NEXT ,MUIM_Notify,MUIA_Pressed            ,FALSE         ,data->GUI.NB_ERROR     ,2,MUIM_Numeric_Increase,1);
  145.          DoMethod(data->GUI.NB_ERROR,MUIM_Notify,MUIA_Numeric_Value      ,MUIV_EveryTime,MUIV_Notify_Application,3,MUIM_CallHook,&ER_SelectHook,MUIV_TriggerValue);
  146.          DoMethod(bt_clear          ,MUIM_Notify,MUIA_Pressed            ,FALSE         ,MUIV_Notify_Application,3,MUIM_CallHook,&ER_CloseHook,TRUE);
  147.          DoMethod(bt_close          ,MUIM_Notify,MUIA_Pressed            ,FALSE         ,MUIV_Notify_Application,3,MUIM_CallHook,&ER_CloseHook,FALSE);
  148.          DoMethod(data->GUI.WI      ,MUIM_Notify,MUIA_Window_CloseRequest,TRUE          ,MUIV_Notify_Application,3,MUIM_CallHook,&ER_CloseHook,FALSE);
  149.          return data;
  150.       }
  151.       free(data);
  152.    }
  153.    return NULL;
  154. }
  155. ///
  156.